import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28318
 * Date: 2025-10-18
 * Time: 16:53
 */
public class Main {

    public static void main(String[] args) {

    }

    public static void main18(String[] args) {
        int[] num1={2,6,4,1};
        int[] num2={1,2,34,3,4,5,7,23,12};
        int[] num3={8,6,54,2,36,9,47,15,3,86,14,5,75,26};
        System.out.println(consecutiveThreeOdd(num1));
        System.out.println(consecutiveThreeOdd(num2));
        System.out.println(consecutiveThreeOdd(num3));
    }

    public static boolean consecutiveThreeOdd(int[] num){
        int count=0;
        for (int i = 0; i < num.length; i++) {
            if(num[i]%2==1){
                count++;
            }
            if(count==3){
                return true;
            }
        }
        return false;
    }

    public static void main17(String[] args) {
        int[] num1={3,2,3};
        int[] num2={2,2,1,1,1,2,2};
        int[] num3={4,4,4,4,4,3,2,4,1,1,2,2,3,4,4,4,4,4};
        System.out.println(mostNum(num1));
        System.out.println(mostNum(num2));
        System.out.println(mostNum(num3));
    }

    public static int mostNum(int[] num){
        sortNum(num);
        return num[num.length/2];
    }

    public static void main16(String[] args) {
        int[] num1={2,2,1};
        int[] num2={4,1,2,1,2};
        int[] num3={5,6,3,4,5,8,6,3,8};
        System.out.println(onlyOneceNum(num1));
        System.out.println(onlyOneceNum(num2));
        System.out.println(onlyOneceNum(num3));
    }

    public static int onlyOneceNum(int[] num){
        int ret=num[0];
        for (int i = 1; i < num.length; i++) {
            ret^=num[i];
        }
        return ret;
    }

    public static void main15(String[] args) {
        int[] num={2,7,11,15,37,101};
        Scanner in_put=new Scanner(System.in);
        System.out.println("请输入要查找的数：");
        int target=in_put.nextInt();
        int[] answer= searchNumSum(num,target);
        if(answer[0]==-1){
            System.out.println("未在数组中查找到和为"+target+"的两个整数");
        }else{
            System.out.println("数组中"+num[answer[0]]+"+"+num[answer[1]]+"="+target);
        }
    }

    public static int[] searchNumSum(int[] num, int target){
        int[] ret={-1,-1};
        for (int i = 0; i < num.length; i++) {
            for (int j = i + 1; j < num.length; j++) {
                if(num[i]+num[j]==target){
                    ret[0]=i;
                    ret[1]=j;
                }
            }
        }
        return ret;
    }

    public static void main14(String[] args) {
        Random random = new Random();
        int n=15;
        int[] num=new int[n];
        for (int i = 0; i < num.length; i++) {
            num[i]=random.nextInt(100);
        }
        System.out.println(Arrays.toString(num));
        sortNum(num);
        System.out.println(Arrays.toString(num));
    }

    public static void sortNum(int[] num){
        for (int i = 0; i < num.length - 1; i++) {
            for (int j = 0; j < num.length - i - 1; j++) {
                if(num[j]>num[j+1]){
                    int swap=num[j];
                    num[j]=num[j+1];
                    num[j+1]=swap;
                }
            }
        }
    }

    public static void main13(String[] args) {
        int[] num = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
        Scanner in_put = new Scanner(System.in);
        System.out.println("请输入在1~16之间需要查找的整数：");
        int n=in_put.nextInt();
        int ret=binSearch(num,n);
        if(ret!=-1){
            System.out.println("数字"+n+"对应的下标是"+ret);
        }else{
            System.out.println("未找到该数字");
        }
    }

    public static int binSearch(int[] num,int n){
        int left=0;
        int right=num.length-1;
        while (left<=right){
            int mid=(left+right)/2;
            if(num[mid]==n){
                return mid;
            }else if(num[mid]>n){
                right=mid-1;
            }else{
                left=mid+1;
            }
        }
        return -1;
    }

    public static void main12(String[] args) {
        int[] num={1,2,3,4,5,6,7,8,9,10};
        System.out.println(Arrays.toString(num));
        swapNum(num);
        System.out.println(Arrays.toString(num));
    }

    public static void swapNum(int[] num){
        int left=0;
        int right=num.length-1;
        while (left<right){
            while (num[left]%2==1){
                left++;
            }
            while (num[right]%2==0){
                right--;
            }
            if(left>=right){
                break;
            }
            int swap=num[left];
            num[left]=num[right];
            num[right]=swap;
        }
    }

    public static void main11(String[] args) {
        int[] num={1,2,3,4,5,6};
        transform(num);
        System.out.println(Arrays.toString(num));
    }

    public static void transform(int[] num){
        for (int i = 0; i < num.length; i++) {
            num[i]*=2;
        }
    }

    public static void main10(String[] args) {
        Scanner in_put = new Scanner(System.in);
        System.out.println("请输入汉诺塔的层数：");
        int n = in_put.nextInt();
        move(n,'A','B','C');
    }

    public static void move(int n,char A,char B,char C){
        if(n==1){
            System.out.println("将圆盘"+n+"从"+A+"柱->"+C+"柱。");
            return;
        }
        move(n-1,A,C,B);
        System.out.println("将圆盘"+n+"从"+A+"柱->"+C+"柱。");
        move(n-1,B,A,C);
    }

    public static void main9(String[] args) {
        System.out.println(maxNum(65,85));
        System.out.println(maxNum(1.6,6.4,3.2));
    }

    public static int maxNum(int a,int b){
        return a>b?a:b;
    }

    public static double maxNum(double a,double b,double c){
        return maxNum(a,b)>c?maxNum(a,b):c;
    }

    public static double maxNum(double a,double b){
        return a>b?a:b;
    }

    public static void main8(String[] args) {
        System.out.println("15+36="+add(15,36));
        System.out.println("3.2+6.4+1.6="+add(3.2,6.4,1.6));
    }

    public static int add(int a,int b){
        return a+b;
    }

    public static double add(double a,double b,double c){
        return a+b+c;
    }

    public static void main7(String[] args) {
        System.out.println("最大数是"+max3(15,68,34));
    }

    public static int max2(int a,int b){
        return a>b?a:b;
    }

    public static int max3(int a,int b,int c){
        return max2(max2(a,b),c);
    }

    public static void main6(String[] args) {
        Scanner in_put = new Scanner(System.in);
        System.out.println("输入要求的整数：");
        int a=in_put.nextInt();
        int count = 0;
        while(a!=0){
            a=a&(a-1);
            count++;
        }
        System.out.println("该数二进制时1的个数为："+count);
    }

    public static void main5(String[] args) {
        Scanner in_put = new Scanner(System.in);
        System.out.println("输入要求最大公约数的两个整数：");
        int a=in_put.nextInt();
        int b=in_put.nextInt();
        if(b>a){
            a=a+b;
            b=a-b;
            a=a-b;
        }
        while(a%b!=0){
            int n=a%b;
            a=b;
            b=n;
            if(b<=1){
                break;
            }
        }
        if(b>1){
            System.out.println(b + "是两数的最大公约数。");
        }else{
            System.out.println("两数没有最大公约数。");
        }
    }

    public static void main4(String[] args) {
        double sum = 0;
        double opp = 1;
        for (double i = 1; i <= 100; i++) {
            sum += 1/i*opp;
            opp = -opp;
        }
        System.out.println("一分之一到百分之一的和为："+sum);
    }

    public static void main3(String[] args) {
        int n = 10000;
        for (int i = 10; i <= n; i++) {
            int count = 0;
            int num = i;
            while(num!=0){
                num/=10;
                count++;
            }
            num = i;
            int sum = 0;
            while(num!=0){
                sum+=Math.pow(num%10,count);
                num/=10;
            }
            if(i==sum){
                System.out.println("数字"+i+"是水仙花数");
            }
        }
    }

    public static void main2(String[] args) {
        int n = 10;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(i==j||i+j==n-1){
                    System.out.print("*");
                }else{
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }

    public static void main1(String[] args) {
        int num = 37;
        boolean prime = true;
        for (int i = 2; i < Math.sqrt(num); i++) {
            if(num%i==0){
                prime = false;
            }
        }
        if(prime==true){
            System.out.println("数字"+num+"是素数。");
        }else{
            System.out.println("数字"+num+"不是素数。");
        }
    }

    public static void main0(String[] args) {
        int n=100;
        int count=0;
        for (int i = 1; i <= n; i++) {
            if(i/90==1|i%10==9){
                count++;
            }
        }
        System.out.println("1~100共有"+count+"个数字9。");
    }

}
